package com.xmj.web.controller.cs;

import com.xmj.common.annotation.Log;
import com.xmj.common.core.controller.BaseController;
import com.xmj.common.core.domain.AjaxResult;
import com.xmj.common.core.page.TableDataInfo;
import com.xmj.common.enums.BusinessType;
import com.xmj.common.utils.poi.ExcelUtil;
import com.xmj.cs.domain.Customers;
import com.xmj.cs.service.ICustomersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 顾客Controller
 *
 * @author ohh
 * @date 2024-04-21
 */
@RestController
@RequestMapping("/cs/Customers")
public class CustomersController extends BaseController
{
    @Autowired
    private ICustomersService customersService;

    /**
     * 查询顾客列表
     */
    @PreAuthorize("@ss.hasPermi('cs:Customers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Customers customers)
    {
        startPage();
        List<Customers> list = customersService.selectCustomersList(customers);
        return getDataTable(list);
    }

    /**
     * 导出顾客列表
     */
    @PreAuthorize("@ss.hasPermi('cs:Customers:export')")
    @Log(title = "顾客", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Customers customers)
    {
        List<Customers> list = customersService.selectCustomersList(customers);
        ExcelUtil<Customers> util = new ExcelUtil<Customers>(Customers.class);
        util.exportExcel(response, list, "顾客数据");
    }

    /**
     * 获取顾客详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:Customers:query')")
    @GetMapping(value = "/{customerID}")
    public AjaxResult getInfo(@PathVariable("customerID") Long customerID)
    {
        return success(customersService.selectCustomersByCustomerID(customerID));
    }

    /**
     * 新增顾客
     */
    @PreAuthorize("@ss.hasPermi('cs:Customers:add')")
    @Log(title = "顾客", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Customers customers)
    {
        return toAjax(customersService.insertCustomers(customers));
    }

    /**
     * 修改顾客
     */
    @PreAuthorize("@ss.hasPermi('cs:Customers:edit')")
    @Log(title = "顾客", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Customers customers)
    {
        return toAjax(customersService.updateCustomers(customers));
    }

    /**
     * 删除顾客
     */
    @PreAuthorize("@ss.hasPermi('cs:Customers:remove')")
    @Log(title = "顾客", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIDs}")
    public AjaxResult remove(@PathVariable Long[] customerIDs)
    {
        return toAjax(customersService.deleteCustomersByCustomerIDs(customerIDs));
    }
}
